Open
Conversation
Currently `Config::load` merges editor configs with
`merge_toml_values(global, local, 3)`
Besides the puzzling use of the magic number `3`, this is a bug,
because it concatenates arrays from the global config file with
those from the local config file.
For example `editor.shell=["bash", "-c"]` and
`editor.shell=["fish", "-c"]` would become
`editor.shell=["bash", "-c", "fish", "-c"]`.
This commit adds a new function `merge_toml_values_with_strategy` and
changes `Config::load` to call:
```
merge_toml_values_with_strategy(
global,
local,
&MergeStrategy {
array: MergeMode::Never,
table: MergeMode::Always,
},
)
```
For backward compatability, the original function `merge_toml_values`
calls:
```
merge_toml_values_with_strategy(
left,
right,
&MergeStrategy {
array: MergeMode::MaxDepth(max_merge_depth),
table: MergeMode::MaxDepth(max_merge_depth),
},
)
```
, so there should be no change in the way themes and languages.toml
are merged.
Also update doc string and add tests.
Split `Config::load` into 2 smaller functions: 1. A function to load a `ConfigRaw` from a path 2. A function to apply a `ConfigRaw` to a `Config` The resulting code is both shorter, more readable, and more extensible (e.g., it can support more than two config files). This refactor revealed the bug described in helix-editor#13332.
bdc2303 to
dcf139c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split
Config::loadinto 2 smaller functions:ConfigRawfrom a pathConfigRawto aConfigThe resulting code is both shorter, more readable, and more extensible (e.g., it can support more than two config files).
This refactor revealed the bug described in helix-editor#13332.